﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;
using System.Web;
using System.IO;
using System.Xml;

namespace WindowsSignInPage
{
    [Serializable]
    [XmlRoot("Config")]
    public class SiteConfig
    {
        [XmlElement("Connection")]
        public string Connection { get; set; }

        [XmlElement("ApplicationUrl")]
        public string ApplicationUrl { get; set; }

        [XmlElement("SharePointUrl")]
        public string SharePointUrl { get; set; }

        [XmlElement("SSOServiceUrl")]
        public string SSOServiceUrl { get; set; }

        [XmlElement("NOPermission")]
        public string NOPermission { get; set; }

        private SiteConfig()
        {
        }

        private static string FilePath
        {
            get
            {
                string configPath = HttpContext.Current.Server.MapPath("~/SiteConfig.xml");
                //string configPath = @"D:\App\NetDisk\ADAuthTest\bin\Debug";// typeof(SiteConfig).Assembly.GetModules()[0].FullyQualifiedName;
                return configPath;
            }
        }
        public static SiteConfig Load()
        {
            if (config == null)
            {
                XmlSerializer ser = new XmlSerializer(typeof(SiteConfig));
                using (XmlReader reader = XmlReader.Create(new StreamReader(FilePath)))
                {
                    config = (SiteConfig)ser.Deserialize(reader);
                    reader.Close();
                    return config;
                }
            }
            return config;
        }

        public static SiteConfig config;
    }
}
